{include file="public/_meta" /}
<body>
<div class="wrapper">

    {include file="public/_header" /}

    <!-- Sidebar -->
    {include file="public/_menu" /}
    <!-- End Sidebar -->

    <div class="main-panel">

        <div class="content">
            <div class="page-inner">

                <!-- 面包屑 -->
                {include file="public/_page_header" /}

                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-header">
                                <div class="d-flex align-items-center">
                                    <h4 class="card-title">账户列表</h4>
                                    {if condition="!in_array($group_id,[7])"}
                                    <a class="btn btn-primary btn-round ml-auto" href="{:url('add')}">
                                        <i class="fa fa-plus"></i>
                                        新增授权
                                    </a>
                                    {/if}
                                </div>

                                <form class="row">
                                    {if condition="!in_array($group_id,[7])"}
                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <select class="form-control" name="admin_id">
                                                <option value="0">全部运营</option>
                                                {volist name="admins" id="vo"}
                                                <option value="{$vo.id}" {if condition="$vo.id eq $admin_id"}selected{/if}>{$vo.realname}</option>
                                                {/volist}
                                            </select>
                                        </div>
                                    </div>


                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <select class="form-control" name="channel_id">
                                                <option value="0">全部媒体</option>
                                                {volist name="channels" id="vo" key="k"}
                                                <option value="{$k}" {if condition="$k eq $channel_id"}selected{/if}>{$vo}</option>
                                                {/volist}
                                            </select>
                                        </div>
                                    </div>
                                    {/if}


                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="adv_id" id="adv_id2" value="{$adv_id}" placeholder="请输入账户ID">
                                        </div>
                                    </div>
                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="acc_name" id="acc_name" value="{$acc_name}" placeholder="请输入账户名称">
                                        </div>
                                    </div>
                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="youhua_name" id="youhua_name" value="{$youhua_name}" placeholder="请输入优化师名称">
                                        </div>
                                    </div>



                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <button type="submit" class="btn btn-primary">查询</button>
                                            <a href="{:url('account/index')}" class="btn btn-info" style="color: white;position: absolute;left: 110px;">重置</a>
                                        </div>
                                    </div>
                                </form>
                            </div>


                            <div class="card-body">
                                <!-- Modal2 -->
                                <div class="modal fade" id="addRowModal2" tabindex="-1" role="dialog" aria-hidden="true">
                                    <div class="modal-dialog" role="document">
                                        <div class="modal-content">
                                            <div class="modal-header no-bd">
                                                <h5 class="modal-title">
                                                    <span class="fw-mediumbold">关联行业</span>

                                                </h5>
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                    <span aria-hidden="true">&times;</span>
                                                </button>
                                            </div>
                                            <div class="modal-body">
                                                <form id="form-modal2">
                                                    <div class="row">

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="acc_name2" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">账户名称</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="acc_name2" disabled>
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="hy_id" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">行业名称</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <select class="form-control input-full" id="hy_id" name="hy_id">
                                                                    <option value="0">请选择</option>
                                                                    {volist name="industrys" id="vo"}
                                                                    <option value="{$vo.id}">{$vo.name}</option>
                                                                    {/volist}
                                                                </select>
                                                            </div>
                                                        </div>


                                                    </div>
                                                    <div class="modal-footer no-bd">
                                                        <input type="hidden" name="id" id="id2" value="">
                                                        <button type="submit" id="addRowButton2" class="btn btn-primary">保存</button>
                                                        <button type="button" class="btn btn-danger" data-dismiss="modal">关闭</button>
                                                    </div>
                                                </form>
                                            </div>

                                        </div>
                                    </div>
                                </div>

                                <div class="modal fade" id="addRowModal3" tabindex="-1" role="dialog" aria-hidden="true">
                                    <div class="modal-dialog" role="document">
                                        <div class="modal-content" style="width: 120%">
                                            <div class="modal-header no-bd">
                                                <h5 class="modal-title">
                                                    <span class="fw-mediumbold">详情</span>

                                                </h5>
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                    <span aria-hidden="true">&times;</span>
                                                </button>
                                            </div>
                                            <div class="modal-body">

                                                <form id="form-modal3">
                                                    <div class="row">

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="acc_name3" class="col-md-3 col-form-label"><font style="vertical-align: inherit;color: red">媒体渠道</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <select class="form-control" name="channel_id" id="channel_ide">
                                                                {volist name="channels" id="vo" key="k"}
                                                                <option value="{$k}" >{$vo}</option>
                                                                {/volist}
                                                                </select>
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="acc_name3" class="col-md-3 col-form-label"><font style="vertical-align: inherit;color: red">账户名称</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="acc_name3" name="acc_name" placeholder="账户名称">
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="acc_desc" class="col-md-3 col-form-label">账户简称<br>
                                                                (商户系统显示)<br>(外链验证码短信签名)</label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="acc_desc" name="acc_desc" placeholder="账户简称">
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="adv_id" class="col-md-3 col-form-label"><font style="vertical-align: inherit;color: red">账户ID</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="adv_id" name="adv_id" placeholder="账户ID">
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="acc_password" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">账户密码</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="acc_password" name="acc_password" placeholder="账户密码">
                                                            </div>
                                                        </div>
                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="acc_password" class="col-md-3 col-form-label"><font style="vertical-align: inherit;color: red">返点</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="clue_rate" name="clue_rate" placeholder="返点百分比例如:10%填10">
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="acc_password" class="col-md-3 col-form-label"><font style="vertical-align: inherit;color: red">渠道别称</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="show_channel" name="show_channel" placeholder="商户端显示的渠道名称">
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="acc_password" class="col-md-3 col-form-label"><font style="vertical-align: inherit;color: red">默认进线单价<br>(只在按A结算时设置)</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="clue_cost" name="clue_cost" placeholder="默认进线单价(只在按A结算时设置)">
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="macc_id" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">管家账户ID</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="macc_id" name="macc_id" placeholder="管家账户ID，如果为普通用户填写账户ID即可">
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="api_token" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">ApiToken</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="api_token" name="api_token" placeholder="ApiToken">
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="ocpc_token" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">转化Token</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="ocpc_token" name="ocpc_token" placeholder="转化Token">
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="ocpc_token" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">选择优化师</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <select class="form-control input-full" name="bind_youhua" id="bind_youhua">
                                                                    <option value="0">--请选择--</option>
                                                                    {volist name="youhua" id="vo"}
                                                                    <option value="{$vo.uid}">【{$vo.realname}】【账号{$vo.phone}】</option>
                                                                    {/volist}
                                                                </select>
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label class="col-md-3 col-form-label">进线是否撞库排重</label>
                                                                <label class="form-radio-label">
                                                                    <input class="form-radio-input" type="radio" name="is_check_repeat" value="1" checked="">
                                                                    <span class="form-radio-sign">&nbsp;&nbsp;是</span>
                                                                </label>
                                                                <label class="form-radio-label ml-3">
                                                                    <input class="form-radio-input" type="radio" name="is_check_repeat" value="2">
                                                                    <span class="form-radio-sign">&nbsp;&nbsp;否</span>
                                                                </label>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="remark" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">备注</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <textarea id="remark" name="remark" class="form-control input-full" style="height: 200px!important"></textarea>
                                                            </div>
                                                        </div>



                                                    </div>
                                                    <div class="modal-footer no-bd">
                                                        <input type="hidden" name="id" id="id3" value="">
                                                        <input type="hidden" name="copy_id" id="copy_id" value="">
                                                        <button type="submit" id="addRowButton" class="btn btn-primary">保存</button>
                                                        <button type="button" class="btn btn-danger" data-dismiss="modal">关闭</button>
                                                    </div>
                                                </form>
                                            </div>

                                        </div>
                                    </div>
                                </div>

                                <div class="table-responsive">
                                    <table id="add-row" class="display table table-striped table-hover" >
                                        <thead>
                                        <tr>
                                            <th>ID</th>
                                            <th>媒体渠道</th>
                                            {if condition="!in_array($group_id,[7])"}
                                            <th>所属行业</th>
                                            {/if}
                                            <th>账户名称</th>
                                            <th>账户ID</th>
                                            {if condition="!in_array($group_id,[7])"}
                                            <th>返点</th>
                                            <th>进线成本</th>
                                            <th>所属运营</th>
                                            <th>是否启用</th>
                                            <th>进线是否撞库</th>
<!--                                            <th>同步状态</th>-->
                                            <th>时间</th>
                                            <th>备注</th>
                                            <th style="width: 10%">操作</th>
                                            {/if}
                                        </tr>
                                        </thead>

                                        <tbody>

                                        {volist name="infos" id="vo"}
                                        <tr>
                                            <td>{$vo.id}</td>
                                            <td>{$vo.channel_name}<br>
                                                {if !empty($vo.show_channel)}
                                                【{$vo.show_channel}】
                                                {/if}
                                            </td>
                                            {if condition="!in_array($group_id,[7])"}
                                            <td>{$vo.hy_name}</td>
                                            {/if}
                                            <td>账号名称：{$vo.acc_name}<br>
                                                账号简称：{$vo.acc_desc}
                                            </td>
                                            <td>{$vo.adv_id}</td>
                                            {if condition="!in_array($group_id,[7])"}
                                            <td>{$vo.clue_rate}%</td>
                                            <td>{$vo.clue_cost}</td>
                                            <td>运营：{$vo.realname}
                                                {if !empty($vo.youhua_name)}
                                                <br>
                                                优化师：{$vo.youhua_name}
                                                {/if}
                                            </td>
                                            <td>{$vo.status|getStatus}</td>
                                            <td>{$vo.is_check_repeat|getStatus}</td>
<!--                                            <td>{$vo.syn_status|getSynStatus}</td>-->
                                            <td>创建时间：{$vo.create_time}<br>
                                                修改时间：{$vo.update_time}
                                            </td>
                                            <td>{$vo.remark}</td>
                                            <td>
                                                <div class="form-button-action">

                                                    <button type="button" title="复制" class="btn btn-success" data-toggle="modal" data-target="#addRowModal3" onClick="edit_item('{$vo.id}', 1)">
                                                        复制
                                                    </button>

                                                    <button type="button" title="编辑" class="btn btn-primary" data-toggle="modal" data-target="#addRowModal3" onClick="edit_item('{$vo.id}')">
                                                        编辑
                                                    </button>

                                                    {if condition="$vo.status eq 1"}

                                                    <button type="button" data-toggle="tooltip" title="" onClick="admin_stop2(this,'{$vo.id}')" class="btn btn-warning btn-sm" data-original-title="停用">
                                                    停用
                                                    </button>


                                                    {else/}

                                                    <button type="button" data-toggle="tooltip" title="" onClick="admin_start2(this,'{$vo.id}')" class="btn btn-success btn-sm" data-original-title="启用">
                                                    启用
                                                    </button>
                                                    {/if}
                                                    &nbsp;&nbsp;

<!--                                                    <button type="button" data-toggle="tooltip" title="" onClick="admin_start(this,'{$vo.id}')" class="btn btn-primary btn-sm" data-original-title="同步">-->
<!--                                                        同步数据-->
<!--                                                    </button>-->
<!--                                                        &nbsp;&nbsp;-->
<!--                                                    <button type="button" data-toggle="tooltip" title="" onClick="admin_stop(this,'{$vo.id}')" class="btn btn-danger btn-sm" data-original-title="暂停">-->
<!--                                                        暂停同步-->
<!--                                                    </button>-->

                                                    <button type="button" title="关联行业" class="btn btn-link btn-primary btn-lg" data-toggle="modal" data-target="#addRowModal2" onClick="edit_item('{$vo.id}')">
                                                        <i class="fa fa-edit"></i>关联行业
                                                    </button>
                                                </div>



                                            </td>
                                            {/if}
                                        </tr>
                                        {/volist}

                                        </tbody>
                                    </table>

                                    <!-- 分页 (调取通用方法)-->
                                     <div class="layui-box layui-laypage layui-laypage-molv">{:pagination($infos)}</div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>


            </div>
        </div>

        {include file="public/_footer" /}


    </div>



</div>

{include file="public/_js" /}

</body>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    var SCOPE = {
        'syn_status_url':"{:url('account/syn_status')}",
        'status_url':"{:url('account/status')}",
        'item_url':"{:url('account/edit')}",
        'add_url':"{:url('account/save')}",
        'copy_url':"{:url('account/copy')}",
    };

    $(function(){
        var commitStatus = false;
        /*表单验证*/
        $("#form-modal3").validate({
            rules:{
                name:{
                    required:true,
                    minlength:2,
                    maxlength:11
                }

            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var url = SCOPE.add_url;
                var id = $("#id3").val()
                if (id == 0) {
                    url =  SCOPE.copy_url;
                }
                if(commitStatus==true){
                    return false;
                }
                /*表单提交*/
                $(form).ajaxSubmit({
                    type: 'post',
                    url: url,
                    success: function(data){
                        if(data.code == 1001){
                            commitStatus==true
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000
                            }, function(){
                                window.location.reload();
                            });
                        }else{
                            layer.msg(data.msg,{icon:2,time:2000});
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer.msg(errorThrown,{icon:2,time:2000});
                    }
                });

            }
        });

    });

    $(function(){
        var commitStatus = false;
        /*表单验证*/

        $("#form-modal2").validate({
            rules:{

            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var url = SCOPE.add_url;
                if(commitStatus==true){
                    return false;
                }

                /*表单提交*/
                $(form).ajaxSubmit({
                    type: 'post',
                    url: url,
                    success: function(data){
                        if(data.code == 1001){
                            commitStatus = true;
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000
                            }, function(){
                                parent.location.reload();
                            });
                        }else{
                            layer.msg(data.msg,{icon:2,time:2000});
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer.msg(errorThrown,{icon:2,time:2000});
                    }
                });

            }
        });

    });

    /*机构-停用*/
    function admin_stop2(obj,id){
        layer.confirm('确认要停用吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……
            var url = SCOPE.status_url;
            $.post(url,{status:2,id:id},function(data){
                if(data.code == 1001){
                    layer.msg('已停用!',{icon: 1,time:1000},function(){
                        window.location.reload();
                    });
                }else{
                    layer.msg(data.msg,{icon: 2,time:1000});
                }

            });


        });
    }


    function edit_item(id, is_copy = 0) {
        $.ajax({
            type: 'GET',
            url: SCOPE.item_url,
            dataType: 'json',
            data: {id:id},
            success: function(res){
                if(res.code == 1001){
                    $("#id2").val(id);
                    $("#id3").val(id);
                    $("#copy_id").val(id);
                    if (is_copy == 1) {
                        $("#id2").val(0);
                        $("#id3").val(0);
                    }
                    $("#hy_id").val(res.data.hy_id);
                    $("#acc_name2").val(res.data.acc_name);
                    $("#acc_name3").val(res.data.acc_name);
                    $("#acc_desc").val(res.data.acc_desc);
                    $("#adv_id").val(res.data.adv_id);
                    $("#acc_password").val(res.data.acc_password);
                    $("#macc_id").val(res.data.macc_id);
                    $("#api_token").val(res.data.api_token);
                    $("#ocpc_token").val(res.data.ocpc_token);
                    $("#show_channel").val(res.data.show_channel);
                    $("#clue_rate").val(res.data.clue_rate);
                    $("#channel_ide").val(res.data.channel_id);
                    $("#clue_cost").val(res.data.clue_cost);
                    $("#bind_youhua").val(res.data.bind_youhua);
                    $("#remark").val(res.data.remark);
                    $(":radio[name='is_check_repeat'][value='"+res.data.is_check_repeat+"']").prop("checked","checked");
                }else{
                    layer.msg(res.msg,{icon:2,time:2000});
                }

            },
            error:function(res) {
                layer.msg('网络错误,稍后再试...',{icon:2,time:2000});
            }
        });
    }

    /*机构-启用*/
    function admin_start2(obj,id){
        layer.confirm('确认要启用吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……

            var url = SCOPE.status_url;
            $.post(url,{status:1,id:id},function(data){
                if(data.code == 1001){

                    layer.msg('已启用!',{icon: 1,time:1000},function(){
                        window.location.reload();
                    });
                }else{
                    layer.msg(data.msg,{icon: 2,time:1000});
                }
            });
        });
    }


    /*机构-停用*/
    function admin_stop(obj,id){
        layer.confirm('确认要暂停吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……
            var url = SCOPE.syn_status_url;
            $.post(url,{status:2,id:id},function(data){
                if(data.code == 1001){
                    layer.msg('已暂停!',{icon: 1,time:2000},function(){
                        window.location.reload();
                    });
                }else{
                    layer.msg(data.msg,{icon: 2,time:2000},function (){
                        window.location.reload();
                    });
                }

            });


        });
    }

    /*机构-启用*/
    function admin_start(obj,id){
        layer.confirm('确认要同步吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……
            var loading = layer.load('加载中...', {
                shade: [0.3,'#fff'] //0.1透明度的白色背景
            });
            var url = SCOPE.syn_status_url;

            $.post(url,{status:1,id:id},function(data){
                layer.close(loading);

                if(data.code == 1001){
                    layer.alert('已同步!', { icon: 1, closeBtn: 0 }, function (index) {
                        window.location.reload();
                    });
                }else{
                    layer.alert(data.msg, { icon: 1, closeBtn: 0 }, function (index) {
                        window.location.reload();
                    });
                }
            });
        });
    }

</script>
</html>




























